package team18.yuejian.Activity;

import android.content.Intent;
import android.media.Image;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import team18.yuejian.Adapter.MineListAdapter;
import team18.yuejian.Adapter.ShowPicAdapter;
import team18.yuejian.Model.MineModel;
import team18.yuejian.R;
import team18.yuejian.RetrofitListener;
import team18.yuejian.bean.OrderBean;

public class MineOrderActivity extends BaseActivity implements View.OnClickListener,RetrofitListener<List<OrderBean>> {

    private ImageView back,type;
    private RecyclerView recyclerView;
    private NavigationView navigationView;
    private TextView Title;
    private MineListAdapter adapter;
    private DrawerLayout drawerLayout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_order);
        initView();
        initEvent();
        initData();
    }

    public void initView(){
        back = findViewById(R.id.MineOrder_back);
        recyclerView = findViewById(R.id.MineOrder_recyclerView);
        navigationView = findViewById(R.id.nav_view);
        Title =findViewById(R.id.MineOrder_Title);
        type = findViewById(R.id.MineOrder_type);

        drawerLayout = findViewById(R.id.drawer_layout);
    }

    public void initEvent(){

        back.setOnClickListener(this);
        type.setOnClickListener(this);


        navigationView.setCheckedItem(R.id.nav_activity);
        int uid = getUserId();
        sendMesage(uid,1,2);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int uid = getUserId();
                switch (item.getItemId()){
                    case R.id.nav_activity:
                            Title.setText("活动订单");
                            sendMesage(uid,1,2);
                        break;
                    case R.id.nav_course:
                        Title.setText("课程订单");
                        sendMesage(uid,2,3);
                        break;
                    case R.id.nav_match:
                        Title.setText("比赛订单");
                        sendMesage(uid,3,4);
                        break;
                    default: break;
                }
                return true;
            }
        });
    }

    public void initData(){

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.MineOrder_back:
                Intent intent = new Intent(MineOrderActivity.this,MineActivity.class);
                startActivity(intent);
                break;
            case R.id.MineOrder_type:
                drawerLayout.openDrawer(GravityCompat.START);
                break;
        }
    }

    @Override
    public void onSuccess(List<OrderBean> orderBeans, int flag) {
        if (orderBeans.size()>0){
            Log.d("数组长度", String.valueOf(orderBeans.size()));
            GridLayoutManager layoutManager = new GridLayoutManager(this,1);
            recyclerView.setLayoutManager(layoutManager);
            adapter = new MineListAdapter(orderBeans,flag-1);
            recyclerView.setAdapter(adapter);
        }else {
            Toast.makeText(MineOrderActivity.this,"无相关订单",Toast.LENGTH_SHORT).show();
        }


    }

    @Override
    public void onFail(String msg) {

    }

    public void sendMesage(int id,int type,int flag){
        MineModel model = new MineModel();
        model.MineGetOrderList(id,type,this,flag);
    }
}
